﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pyramid.Hardware;
using Pyramid.Hardware.Operations;
using Pyramid.Hardware.Interop;

namespace Pyramid.Tests
{
    [TestClass]
    public class FullAdderFixture
    {
        [TestMethod]
        public void ShouldPerformAllFullAdds()
        {
            int[][] testData = new int[][]
                {
                    new int[]{1, 1, 1, 0, 1},
                    new int[]{1, 0, 1, -1, 1},
                    new int[]{1, -1, 1, 1, 0},
                    new int[]{0, 1, 1, -1, 1},
                    new int[]{0, 0, 1, 1, 0},
                    new int[]{0, -1, 1, 0, 0},
                    new int[]{-1, 1, 1, 1, 0},
                    new int[]{-1, 0, 1, 0, 0},
                    new int[]{-1, -1, 1, -1, 0},

                    new int[]{1, 1, 0, -1, 1},
                    new int[]{1, 0, 0, 1, 0},
                    new int[]{1, -1, 0, 0, 0},
                    new int[]{0, 1, 0, 1, 0},
                    new int[]{0, 0, 0, 0, 0},
                    new int[]{0, -1, 0, -1, 0},
                    new int[]{-1, 1, 0, 0, 0},
                    new int[]{-1, 0, 0, -1, 0},
                    new int[]{-1, -1, 0, 1, -1},

                    new int[]{1, 1, -1, 1, 0},
                    new int[]{1, 0, -1, 0, 0},
                    new int[]{1, -1, -1, -1, 0},
                    new int[]{0, 1, -1, 0, 0},
                    new int[]{0, 0, -1, -1, 0},
                    new int[]{0, -1, -1, 1, -1},
                    new int[]{-1, 1, -1, -1, 0},
                    new int[]{-1, 0, -1, 1, -1},
                    new int[]{-1, -1, -1, 0, -1}
                };

            foreach (var row in testData)
            {
                ShouldPerformFullAdd(row[0], row[1], row[2], row[3], row[4]);
            }
        }

        public void ShouldPerformFullAdd(int A, int B, int CarryIn, int ExpectedSum, int ExpectedCarry)
        {
            FullAdder fullAdder = new FullAdder(new VariableInputLine(A), new VariableInputLine(B), new VariableInputLine(CarryIn));
            Assert.AreEqual((Trivalent)ExpectedSum, fullAdder.Sum.Signal);
            Assert.AreEqual((Trivalent)ExpectedCarry, fullAdder.Carry.Signal);
        }
    }
}
